package chenji.gunapi.bullet.player;

import java.util.HashMap;
import java.util.Map;

import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import chenji.gunapi.GunAPI;
import chenji.gunapi.events.MouseClickEvent.MouseButtonType;
import chenji.gunapi.gun.Gun;
import chenji.gunapi.task.Taskable;
import chenji.gunapi.untl.nbt.NMSItem;

public class PlayerGunManager implements Taskable {
	public PlayerGunManager() {
		GunAPI.getGunAPI().getGunTaskManager().registerPerTickTask(this);
	}

	private Map<Player, PlayerGun> holdinggun = new HashMap<>();

	public void holdGun(Gun g, Player p) {
		PlayerGun pg = new PlayerGun(p, g, g.getFullBulletAmount());
		this.holdinggun.put(p, pg);
		return;
	}

	public void getState() {
	}

	public void putDownGun(Player p) {
		if (this.holdinggun.containsKey(p)) {
			
	
			this.holdinggun.remove(p);
			
		}
	
	}

	public void task() {
		for (Player p : this.holdinggun.keySet()) {
			this.holdinggun.get(p).Task();
		}
	}

	public void updateMouseState(MouseButtonType b, boolean state, Player p) {
		if (this.holdinggun.containsKey(p)) {
			this.holdinggun.get(p).updateMouseEvent(b, state);
		}
	}

	public boolean isHolding(Player player) {
		return this.holdinggun.containsKey(player);
	}

	public ItemStack setAmount(ItemStack i, int amount) {
		NMSItem m = NMSItem.getNMSItem(i);
		m.setInteger("amount", amount);
		return m.getItem();

	}

	public int getAmount(ItemStack i) {
		NMSItem m = NMSItem.getNMSItem(i);
		return m.getInteger("amount");
	}

}
